// src/api/merchant.js
import request from '@/utils/request'

// 获取商家店铺信息
export function getShopInfo() {
  return request({
    url: '/api/v1/merchant/shop',
    method: 'get'
  })
}

// 更新商家店铺信息
export function updateShopInfo(data) {
  return request({
    url: '/api/v1/merchant/shop',
    method: 'put',
    data
  })
}

// 上传店铺logo
export function uploadShopLogo(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/api/v1/merchant/shop/logo',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// ==================== 商家管理（管理员使用）====================
// 获取商家列表
export function getMerchantList(params) {
  return request({
    url: '/api/v1/admin/merchants',
    method: 'get',
    params: {
      page: params.pageNum,
      size: params.pageSize,
      ...params
    }
  })
}

// 搜索商家
export function searchMerchants(params) {
  return request({
    url: '/api/v1/admin/merchants/search',
    method: 'get',
    params: {
      keyword: params.keyword,
      page: params.pageNum,
      size: params.pageSize
    }
  })
}

// 获取商家详情
export function getMerchantDetail(id) {
  return request({
    url: `/api/v1/admin/merchants/${id}`,
    method: 'get'
  })
}

// 获取非审核通过的商家列表
export function getNonApprovedMerchants(params) {
  return request({
    url: '/api/v1/admin/merchants/non-approved',
    method: 'get',
    params: {
      page: params.pageNum,
      size: params.pageSize,
      ...params
    }
  })
}

// 审核商家
export function auditMerchant(id, data) {
  return request({
    url: `/api/v1/admin/merchants/${id}/audit`,
    method: 'post',
    data
  })
}

// 更新商家状态
export function updateMerchantStatus(id, status) {
  return request({
    url: `/api/v1/admin/merchants/${id}/status?status=${status}`,
    method: 'put'
  })
}

// ==================== 商家统计 ====================
// 获取商家统计概览
export function getMerchantOverview() {
  return request({
    url: '/api/v1/merchant/statistics/overview',
    method: 'get'
  })
}

// 获取商家销售统计
export function getMerchantSalesStatistics(params) {
  return request({
    url: '/api/v1/merchant/statistics/sales',
    method: 'get',
    params
  })
}

// 获取商家订单统计
export function getMerchantOrderStatistics(params) {
  return request({
    url: '/api/v1/merchant/statistics/orders',
    method: 'get',
    params
  })
}

// 获取商家商品统计
export function getMerchantProductStatistics(params) {
  return request({
    url: '/api/v1/merchant/statistics/products',
    method: 'get',
    params
  })
}

// 获取商家评论统计
export function getMerchantCommentStatistics(params) {
  return request({
    url: '/api/v1/merchant/statistics/comments',
    method: 'get',
    params
  })
}

// 获取商家退款统计
export function getMerchantRefundStatistics(params) {
  return request({
    url: '/api/v1/merchant/statistics/refunds',
    method: 'get',
    params
  })
}